
class EventShop {
    constructor(){
        this.eventList = {};
        
    }
    publish(name, ...arg){
        let event = this.eventList[name];
        if(event){
           event.forEach(val => {
                val.apply(null,arg);
           })
        }
    }
    subscribe(name, fn){
        if(this.eventList[name]) {
            this.eventList[name].push(fn);
        }else {
            this.eventList[name] = [];
            this.eventList[name].push(fn);
        }
        
    }
    unSubscribe(name){
        this.eventList[name] = '';
        delete this.eventList[name];
    }
}
module.exports = new EventShop();